# -*- python -*-
# ex: set syntax=python:

# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# It has one job: define a dictionary named BuildmasterConfig. This
# dictionary has a variety of keys to control different aspects of the
# buildmaster. They are documented in docs/config.xhtml .

from buildbot.scheduler import Dependent
from buildbot.scheduler import Scheduler
from buildbot.scheduler import Periodic
from buildbot.schedulers import triggerable

from common import chromium_utils
from master import build_utils
from master import master_utils
from master import slaves_list
from master.factory import gclient_factory, annotator_factory
from master.factory.dart import dart_factory
from master.factory.dart.dart_factory import (linux_env, windows_env,
    linux_clang_env, linux_asan_env_32, linux_asan_env_64)
from master.factory.dart.channels import CHANNELS

from twisted.python import log

import config
import master_site_config
ActiveMaster = master_site_config.Dart
utils = dart_factory.DartUtils(ActiveMaster)

# Hack to increase timeout for steps, dart2js debug checked mode takes more
# than 8 hours.
utils.monkey_patch_remoteshell()

MASTER_HOST = ActiveMaster.master_host
WEB_STATUS = True
MAIL_NOTIFIER = ActiveMaster.is_production_host
GOOD_REVISIONS = ActiveMaster.is_production_host

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

config.DatabaseSetup(c, require_dbconfig=ActiveMaster.is_production_host)

# 'slavePortnum' defines the TCP port to listen on. This must match the value
# configured into the buildslaves (with their --master option)
c['slavePortnum'] = ActiveMaster.slave_port

slaves = slaves_list.SlavesList('slaves.cfg', 'Dart')

def setup_channel(channel):
  postfix = channel.builder_postfix

  ####### Variant definitions
  # build-base-name, category, platform, builder, tester
  # env are relative to the dart root directory.

  def category(name):
    return '%d%s%s|all' % (channel.position, name, channel.category_postfix)

  variants = [
    {
      'name': 'vm-mac-debug-ia32' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'debug',
      'arch': 'ia32',
    },
    {
      'name': 'vm-mac-debug-x64' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'debug',
      'arch': 'x64',
    },
    {
      'name': 'vm-mac-release-ia32' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'ia32',
    },
    {
      'name': 'vm-mac-release-x64' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'x64',
    },
    {
      'name': 'vm-linux-debug-ia32' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'debug',
      'arch': 'ia32',
      'env': linux_clang_env,
    },
    {
      'name': 'vm-linux-debug-x64' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'debug',
      'arch': 'x64',
      'env': linux_clang_env,
    },
    {
      'name': 'vm-linux-release-x64-asan' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'x64',
      'env': linux_asan_env_64,
    },
    {
      'name': 'vm-linux-release-ia32-asan' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'ia32',
      'env': linux_asan_env_32,
    },
    {
      'name': 'vm-linux-release-ia32' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'ia32',
      'env': linux_clang_env,
    },
    {
      'name': 'vm-linux-release-x64' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'x64',
      'env': linux_clang_env,
    },
    {
      'name': 'vm-linux-release-optcounter-threshold' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'vm_options': '--optimization-counter-threshold=5',
      'arch': 'ia32,x64',
      'env': linux_clang_env,
    },
    {
      'name': 'vm-mips-sim-debug' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'debug',
      'arch': 'simmips',
      'env': linux_env,
    },
    {
      'name': 'vm-mips-sim-release' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'simmips',
      'env': linux_env,
    },
    {
      'name': 'vm-arm-sim-debug' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'debug',
      'arch': 'simarm',
      'env': linux_env,
    },
    {
      'name': 'vm-arm-sim-release' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'simarm',
      'env': linux_env,
    },
    {
      'name': 'vm-arm64-sim-release' + postfix,
      'category': category('1vm'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'simarm64',
      'env': linux_env,
    },
    {
      'name': 'vm-win32-debug' + postfix,
      'category': category('1vm'),
      'platform': 'windows' + postfix,
      'mode': 'debug',
      'arch': 'ia32',
      'env': windows_env,
    },
    {
      'name': 'vm-win32-release' + postfix,
      'category': category('1vm'),
      'platform': 'windows' + postfix,
      'mode': 'release',
      'arch': 'ia32',
      'env': windows_env,
    },
    {
      'name': 'vm-win32-debug-russian' + postfix,
      'category': category('1vm'),
      'platform': 'windows' + postfix,
      'mode': 'debug',
      'arch': 'ia32',
      'env': windows_env,
    },
    {
      'name': 'vm-win64-release' + postfix,
      'category': category('1vm'),
      'platform': 'windows' + postfix,
      'mode': 'release',
      'arch': 'x64',
      'env': windows_env,
    },
    {
      'name': 'vm-win64-debug' + postfix,
      'category': category('1vm'),
      'platform': 'windows' + postfix,
      'mode': 'debug',
      'arch': 'x64',
      'env': windows_env,
    },
    {
      'name': 'cross-arm-vm-linux-release' + postfix,
      'category': category('1vm'),
      'platform': 'posix-standalone' + postfix,
      'mode': 'release',
      'arch': 'arm',
      'triggers' : [{
        'schedulerNames': ['scheduler-arm' + postfix],
        'waitForFinish': False,
        'updateSourceStamp': False,
      }],
      'env': linux_env,
    },
    {
      'name': 'dart-sdk-linux' + postfix,
      'category': category('4dart-sdk'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart-sdk-windows' + postfix,
      'category': category('4dart-sdk'),
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'dart-sdk-mac' + postfix,
      'category': category('4dart-sdk'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'dart2js-linux-release-minified-1-5' + postfix,
      'category': category('20dart2js'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-minified-2-5' + postfix,
      'category': category('20dart2js'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-minified-3-5' + postfix,
      'category': category('20dart2js'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-minified-4-5' + postfix,
      'category': category('20dart2js'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-minified-5-5' + postfix,
      'category': category('20dart2js'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-checked-1-5' + postfix,
      'category': category('21dart2js-checked'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-checked-2-5' + postfix,
      'category': category('21dart2js-checked'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-checked-3-5' + postfix,
      'category': category('21dart2js-checked'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-checked-4-5' + postfix,
      'category': category('21dart2js-checked'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-release-checked-5-5' + postfix,
      'category': category('21dart2js-checked'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-jsshell-release-1-4' + postfix,
      'category': category('22dart2js-jsshell'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-jsshell-release-2-4' + postfix,
      'category': category('22dart2js-jsshell'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-jsshell-release-3-4' + postfix,
      'category': category('22dart2js-jsshell'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-linux-jsshell-release-4-4' + postfix,
      'category': category('22dart2js-jsshell'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'analyzer_experimental-linux-release' + postfix,
      'category': category('30analyzer'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'ia32',
      'env': linux_env,
    },
    {
      'name': 'dart2js-drt-linux-1-2' + postfix,
      'category': category('8chrome'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-drt-linux-2-2' + postfix,
      'category': category('8chrome'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'dart2js-drt-linux-csp' + postfix,
      'category': category('8chrome'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'full-linux-1-4' + postfix,
      'category': category('7dart2js-linux'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'full-linux-2-4' + postfix,
      'category': category('7dart2js-linux'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'full-linux-3-4' + postfix,
      'category': category('7dart2js-linux'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'full-linux-4-4' + postfix,
      'category': category('7dart2js-linux'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'full-win7-ie10-1-4' + postfix,
      'category': category('92dart2js-windows'),
      'builddir': 'ie10-1-4' + postfix,
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'full-win7-ie10-2-4' + postfix,
      'category': category('92dart2js-windows'),
      'builddir': 'ie10-2-4' + postfix,
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'full-win7-ie10-3-4' + postfix,
      'category': category('92dart2js-windows'),
      'builddir': 'ie10-3-4' + postfix,
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'full-win7-ie10-4-4' + postfix,
      'category': category('92dart2js-windows'),
      'builddir': 'ie10-4-4' + postfix,
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'full-win7-ie11-1-4' + postfix,
      'category': category('92dart2js-windows'),
      'builddir': 'ie11-1-4' + postfix,
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'full-win7-ie11-2-4' + postfix,
      'category': category('92dart2js-windows'),
      'builddir': 'ie11-2-4' + postfix,
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'full-win7-ie11-3-4' + postfix,
      'category': category('92dart2js-windows'),
      'builddir': 'ie11-3-4' + postfix,
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'full-win7-ie11-4-4' + postfix,
      'category': category('92dart2js-windows'),
      'builddir': 'ie11-4-4' + postfix,
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'dart2js-ie10-win8-html' + postfix,
      'category': category('91ie'),
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'dart2js-ie11-win8-html' + postfix,
      'category': category('91ie'),
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'dart2js-safari-mac10.8' + postfix,
      'builddir': '10.8' + postfix,
      'category': category('90safari'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'dart2js-safari-mac10.9-1-3' + postfix,
      'builddir': '10.9-1' + postfix,
      'category': category('90safari'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'dart2js-safari-mac10.9-2-3' + postfix,
      'builddir': '10.9-2' + postfix,
      'category': category('90safari'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'dart2js-safari-mac10.9-3-3' + postfix,
      'builddir': '10.9-3' + postfix,
      'category': category('90safari'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'dart2js-safarimobilesim-mac10.8' + postfix,
      'builddir': 'mobile' + postfix,
      'category': category('90safari'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'dart2js-chrome-mac10.9' + postfix,
      'builddir': '10.9-c' + postfix,
      'category': category('8chrome'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'pub-mac' + postfix,
      'category': category('94pub-pkg'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'pub-linux' + postfix,
      'category': category('94pub-pkg'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'pub-win' + postfix,
      'category': category('94pub-pkg'),
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'pub-win-russian' + postfix,
      'category': category('94pub-pkg'),
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'pub-mac-debug' + postfix,
      'category': category('94pub-pkg'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'pub-linux-debug' + postfix,
      'category': category('94pub-pkg'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'pub-win-debug' + postfix,
      'category': category('94pub-pkg'),
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
    {
      'name': 'version-checker' + postfix,
      'category': category('99misc'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
    {
      'name': 'linux-distribution-support-debian_wheezy' + postfix,
      'category': category('99misc'),
      'platform': 'posix' + postfix,
    },
  ]

  variants_editor_linux = [
    {
      'name': 'dart-editor-linux' + postfix,
      'category': category('4dart-editor'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    },
  ]
  variants_editor_mac = [
    {
      'name': 'dart-editor-mac' + postfix,
      'category': category('4dart-editor'),
      'platform': 'posix' + postfix,
    },
  ]
  variants_editor_win = [
    {
      'name': 'dart-editor-win' + postfix,
      'category': category('4dart-editor'),
      'platform': 'windows' + postfix,
      'env': windows_env,
    },
  ]

  variants_editor_installer = [
    {
      'name': 'dart-editor-installer-mac' + postfix,
      'category': category('4dart-editor'),
      'platform': 'posix' + postfix,
    },
    {
      'name': 'dart-editor-installer-win' + postfix,
      'category': category('4dart-editor'),
      'platform': 'windows-wix' + postfix,
    },
  ]

  # Only run ie 9 tests on stable channel
  if channel.name == 'stable':
    variants.append({
      'name': 'dart2js-ie9-win7-all' + postfix,
      'category': category('92dart2js-windows'),
      'platform': 'windows' + postfix,
      'env': windows_env,
    })

  variants_arm = [
    {
      'name': 'target-arm-vm-linux-release' + postfix,
      'category': category('1vm-arm'),
      'platform': 'posix-standalone-noRunhooks' + postfix,
      'mode': 'release',
      'arch': 'arm',
      'env': linux_env,
    },
  ]

  variants_dartium = []

  ####### Don't run dartium-inc on dev/stable
  if channel.name == 'be' or channel.name == 'integration':
    variants_dartium.extend([
      {
        'name' : 'dartium-mac-inc' + postfix,
        'category' : category('6dartium-inc'),
      },
      {
        'name' : 'dartium-lucid64-inc' + postfix,
        'category' : category('6dartium-inc'),
      },
      {
        'name': 'dartium-win-inc-ninja' + postfix,
        'category' : category('6dartium-inc'),
      },
    ])

  variants_dartium_full_mac = [
    {
      'name' : 'dartium-mac-full' + postfix,
      'category' : category('97dartium-full'),
    },
  ]

  variants_dartium_full_linux = [
    {
      'name' : 'dartium-lucid64-full' + postfix,
      'category' : category('97dartium-full'),
    },
    {
      'name' : 'dartium-lucid32-full' + postfix,
      'category' : category('97dartium-full'),
    },
  ]

  variants_dartium_full_win = [
    {
      'name' : 'dartium-win-full' + postfix,
      'category' : category('97dartium-full'),
    },
  ]

  # Build content_shell for android on all channels.
  # This builder is not set up using setup_dartium_factories. It uses recipes.
  if channel.name == 'be':
    android_factory_properties = {
        'deps_url': 'https://github.com/dart-lang/sdk.git',
        'deps_path': 'src/dart',
    }
  else:
    android_factory_properties = {
        'deps_url': config.Master.dart_url + channel.dartium_deps_path,
        'deps_path': 'dartium.deps',
    }

  variants_dartium_android_release = [
    {
      'name': 'dartium-android-release' + postfix,
      'category': category('61dartium-android'),
      'factory_builder': annotator_factory.AnnotatorFactory().BaseFactory(
                             recipe='dart/dartium_android_builder',
                             factory_properties=android_factory_properties),
      'platform': 'android' + postfix,
      'env': linux_env,
    }
  ]

  # Sort of hackish, but easy until this hits through on all channels
  # Don't run editor bots and java based analyzer on bleeding edge
  if channel.name == 'be' or channel.name == 'dev':
    variants_editor_linux = []
    variants_editor_mac = []
    variants_editor_win = []
    variants_editor_installer = []
  else:
    variants.append({
      'name': 'dart-editor' + postfix,
      'category': category('4dart-editor'),
      'platform': 'posix' + postfix,
      'env': linux_env,
    })
    variants.append(    {
      'name': 'new_analyzer-linux-release' + postfix,
      'category': category('30analyzer'),
      'platform': 'posix' + postfix,
      'mode': 'release',
      'arch': 'ia32',
      'env': linux_env,
    })


  ####### Dartium integration overrides, we only use the dartium builders there
  if channel.name == 'integration':
    variants = []
    variants_editor_linux = []
    variants_editor_mac = []
    variants_editor_win = []
    variants_editor_installer = []
    variants_arm = []


  ####### Factory setup

  utils.setup_factories(variants)
  utils.setup_factories(variants_editor_linux)
  utils.setup_factories(variants_editor_mac)
  utils.setup_factories(variants_editor_win)
  utils.setup_factories(variants_editor_installer)
  utils.setup_factories(variants_arm)
  utils.setup_dartium_factories(variants_dartium)
  utils.setup_dartium_factories(variants_dartium_full_mac)
  utils.setup_dartium_factories(variants_dartium_full_linux)
  utils.setup_dartium_factories(variants_dartium_full_win)

  ####### Schedulers

  # builder names
  builder_names = utils.get_builder_names(variants)
  builder_names_linux_editor = utils.get_builder_names(variants_editor_linux)
  builder_names_mac_editor = utils.get_builder_names(variants_editor_mac)
  builder_names_installer = utils.get_builder_names(variants_editor_installer)
  builder_names_win_editor = utils.get_builder_names(variants_editor_win)
  builder_names_arm = utils.get_builder_names(variants_arm)
  dartium_builder_names = utils.get_builder_names(variants_dartium)
  dartium_full_linux_builder_names = (
      utils.get_builder_names(variants_dartium_full_linux))
  dartium_full_mac_builder_names = (
      utils.get_builder_names(variants_dartium_full_mac))
  dartium_full_win_builder_names = (
      utils.get_builder_names(variants_dartium_full_win))
  dartium_android_release_builder_names = (
      utils.get_builder_names(variants_dartium_android_release))

  c['schedulers'].append(triggerable.Triggerable(
      name='scheduler-arm' + postfix,
      builderNames=builder_names_arm,
  ))

  if channel.name in ['be', 'integration']:
    # normal builders + editor builders + dartium builders
    c['schedulers'].append(Scheduler(
        name='main' + postfix,
        branch=channel.branch,
        treeStableTimer=0,
        builderNames=builder_names +
                     builder_names_linux_editor +
                     builder_names_mac_editor +
                     builder_names_win_editor +
                     dartium_builder_names +
                     dartium_full_linux_builder_names +
                     dartium_full_mac_builder_names +
                     dartium_full_win_builder_names +
                     dartium_android_release_builder_names
    ))
  else:
    c['schedulers'].append(Scheduler(
        name='main' + postfix,
        branch=channel.branch,
        treeStableTimer=0,
        builderNames=builder_names + dartium_builder_names +
                     dartium_android_release_builder_names))

    s_dartium_linux = Scheduler(
        name='dartium-linux' + postfix,
        branch=channel.branch,
        treeStableTimer=0,
        builderNames=dartium_full_linux_builder_names)
    s_dartium_mac = Scheduler(
        name='dartium-mac' + postfix,
        branch=channel.branch,
        treeStableTimer=0,
        builderNames=dartium_full_mac_builder_names)
    s_dartium_win = Scheduler(
        name='dartium-win' + postfix,
        branch=channel.branch,
        treeStableTimer=0,
        builderNames=dartium_full_win_builder_names)
    c['schedulers'].append(s_dartium_linux)
    c['schedulers'].append(s_dartium_mac)
    c['schedulers'].append(s_dartium_win)

    c['schedulers'].append(Dependent(
        name='dartium-dependend-linux' + postfix,
        builderNames = builder_names_linux_editor,
        upstream = s_dartium_linux
    ))
    c['schedulers'].append(Dependent(
        name='dartium-dependend-mac' + postfix,
        builderNames = builder_names_mac_editor,
        upstream = s_dartium_mac
    ))
    c['schedulers'].append(Dependent(
        name='dartium-dependend-win' + postfix,
        builderNames = builder_names_win_editor,
        upstream = s_dartium_win
    ))

  ####### Builders

  # Add non-dartium builders
  for collection in [variants, variants_editor_linux, variants_editor_mac,
                     variants_editor_win, variants_arm,
                     variants_editor_installer,
                     variants_dartium_android_release]:
    for b in utils.get_builders_from_variants(collection, slaves, []):
      c['builders'].append(b)

  # Add dartium builders
  for collection in [variants_dartium, variants_dartium_full_linux,
                     variants_dartium_full_mac, variants_dartium_full_win]:
    # Reboot VMs after every build
    for b in utils.get_builders_from_variants(collection, slaves, [],
                                              ActiveMaster.is_production_host):
      c['builders'].append(b)

c['builders'] = []
c['schedulers'] = []
for channel in CHANNELS:
  setup_channel(channel)

####### CHANGESOURCES

c['change_source'] = [
    utils.get_svn_poller(),
    utils.get_github_poller('dart-lang', 'sdk', master='main'),
    utils.get_github_poller('dart-lang', 'sdk', branch='dev', master='main')]

####### BUILDSLAVES

c['slaves'] = utils.get_slaves(c['builders'])

# Make sure everything works together.
master_utils.VerifySetup(c, slaves)

# Prioritize the builders depending on channel.
c['prioritizeBuilders'] = utils.prioritize_builders

####### STATUS TARGETS

# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# including web pages, email senders, and IRC bots.

c['status'] = []

if WEB_STATUS:
  for status in utils.get_web_statuses():
    c['status'].append(status)

if MAIL_NOTIFIER:
  # We have people that are interested in a specific subset of the builders
  # and want to be notified whenever they break.
  mail_notifiers = [
    {
      'extraRecipients': ['ricow+botfailures@google.com',
                          'whesse+botfailures@google.com',],
      'builders': None,  # None means all builders
      'sendToInterestedUsers': True,
    },
    {
      'extraRecipients': ['ricow@google.com', 'whesse@google.com',
                          'kasperl@google.com'],
      'builders': ['version-checker-dev', 'version-checker-stable'],
      'subject': 'VERSION file breakage - bad build',
      'sendToInterestedUsers': True,
    },
    {
      'extraRecipients' : ['zra@google.com',
                           'whesse@google.com',
                           'ricow@google.com'],
      'builders' : ['dartium-android-release'],
      'subject' : 'Dartium android content-shell builder broke',
    }

  ]

  for notifier in utils.get_mail_notifier_statuses(mail_notifiers):
    c['status'].append(notifier)

if GOOD_REVISIONS:
  from master import goodrevisions
  # We use this basically to decide if the vm in release mode, dart2js on d8,
  # and dartium inc succeeded.
  factory_map = []
  def is_important(name):
    # Only bleeding edge builds matter
    if not name.endswith('-be'):
      return False
    # Linux vm and dart2js v8 bots
    important = ['vm-linux-release-ia32', 'vm-linux-release-x64',
                 'dart2js-linux-release-minified']
    for prefix in important:
      if name.startswith(prefix):
        return True
    if 'dartium' in name and '-inc' in name:
      return True

  for b in c['builders']:
    if is_important(b['name']):
      factory_map.append((b['name'], b['factory']))

  log.msg("LKGR based on: %s " % [b[0] for b in factory_map])

  any_steps = build_utils.ExtractFactoriesSteps(factory_map)
  c['status'].append(goodrevisions.GoodRevisions(
      good_revision_steps=any_steps,
      store_revisions_url=ActiveMaster.store_revisions_url))


# Keep last build logs, the default is too low.
c['buildHorizon'] = 1000
c['logHorizon'] = 500
# Must be at least 2x the number of slaves.
c['eventHorizon'] = 200

# Template generation is using 40 entries, so give it a little extra.
c['buildCacheSize'] = 42

c['properties'] = {'mastername': master_utils.GetMastername()}

####### PROJECT IDENTITY

# the 'projectName' string will be used to describe the project that this
# buildbot is working on. For example, it is used as the title of the
# waterfall HTML page. The 'projectURL' string will be used to provide a link
# from buildbot HTML pages to your project's home page.

c['projectName'] = ActiveMaster.project_name
c['projectURL'] = config.Master.project_url

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.Waterfall page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

c['buildbotURL'] = ActiveMaster.buildbot_url
